// 重复的DNA序列

package Leetcode;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

class Solution187 {
    public List<String> findRepeatedDnaSequences(String s) {
        Map<String, Integer> map = new HashMap<>();
        int sublen = 10;
        for (int i = 0; i < s.length() - sublen; i++) {
            String sub = s.substring(i, i + sublen);
            if (map.containsKey(sub))
                map.put(sub, map.get(sub) + 1);
            else
                map.put(sub, 1);
        }
        List<String> result = new ArrayList<>();
        for (Map.Entry<String, Integer> entrySet : map.entrySet()) {
            if (entrySet.getValue() > 1)
                result.add(entrySet.getKey());
        }
        return result;
    }
}